//
//  AppMacros.h
//  imtMall
//
//  Created by Onliu on 14-6-6.
//  Copyright (c) 2014年 Onliu. All rights reserved.
//


// Release a CoreFoundation object safely.
#define MM_RELEASE_CF_SAFELY(__REF) { if (nil != (__REF)) { CFRelease(__REF); __REF = nil; } }


//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#define APP_VERSION ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])

//系统版本：
#define IOS8_OR_LATER	( [[[UIDevice currentDevice] systemVersion] floatValue] >= 8 )
#define IOS7_OR_LATER	( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7 )
#define IOS6_OR_LATER	( [[[UIDevice currentDevice] systemVersion] floatValue] >= 6 )
#define IOS5_OR_LATER	( [[[UIDevice currentDevice] systemVersion] floatValue] >= 5 )
#define IOS4_OR_LATER	( [[[UIDevice currentDevice] systemVersion] floatValue] >= 4 )

#define IS_IOS8	( [[[UIDevice currentDevice] systemVersion] intValue] == 8 )
#define IS_IOS7	( [[[UIDevice currentDevice] systemVersion] intValue] == 7 )
#define IS_IOS6	( [[[UIDevice currentDevice] systemVersion] intValue] == 6 )
#define IS_IOS5	( [[[UIDevice currentDevice] systemVersion] intValue] == 5 )
#define IS_IOS4	( [[[UIDevice currentDevice] systemVersion] intValue] == 4 )

#define KEY_WINDOW  [UIApplication sharedApplication].keyWindow

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
#define IOS7_SDK_AVAILABLE 1
#endif

#define IOS7_NAVI_SPACE -10

//获取当前语言
#define CurrentLanguage ([[[NSBundle mainBundle] preferredLocalizations] firstObject])

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define iPhone4s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad ([[[UIDevice currentDevice] model] rangeOfString:@"iPad"].location != NSNotFound)
#define isSimulator (NSNotFound != [[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location)


//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)

//屏幕长宽
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define NavigationBar_HEIGHT_iOS7_Later     64
#define NavigationBar_HEIGHT 44     //导航栏高度
#define StatusBar_HEIGHT 20         //状态栏高度
#define TABBAR_HEIGHT  49

//G－C－D
#define QUEUE_BACKGROUND    dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define QUEUE_MAIN          dispatch_get_main_queue()
#define MainQueue(queue) dispatch_async(dispatch_get_main_queue(), queue);


#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

#pragma mark - Setting
//当前系统设置国家的country iso code
#define countryISO  [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]
//当前系统设置语言的iso code
#define languageISO [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]

#pragma mark - Path
#define kHomePath            NSHomeDirectory()
#define kCachePath          [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]
#define kDocumentFolder     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define kDocumentFolder2    [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
#define kLibraryPath        [NSHomeDirectory() stringByAppendingPathComponent:@"Library"]

#define kTempPath            NSTemporaryDirectory()
#define kMainBoundPath      [[NSBundle mainBundle] bundlePath]
#define kResourcePath       [[NSBundle mainBundle] resourcePath]
#define kExecutablePath     [[NSBundle mainBundle] executablePath]


#define WEAK_SELF           __weak __typeof(self) weakSelf = self;
#define STRONG_SELF         __strong __typeof(self) strongSelf = weakSelf;


#pragma mark Time
#define TICK   NSDate *startTime = [NSDate date]
#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])

#define LOADNIBWITHSTRING(string)  [[NSBundle mainBundle] loadNibNamed:(string) owner:nil options:nil][0]


//----------------------------------------方法组装相关-------------------------
#define MSTRINGWITHINT(A) [NSString stringWithFormat:@"%d", A]
#define MSTRINGWITHFLOAT(A) [NSString stringWithFormat:@"%f", A]
#define MGETSTRING(A) A?A:@""


/*********************** Color ***************************/
#pragma mark- Color
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define HexColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define kColor_clearColor           ([UIColor clearColor])
#define kColor_redColor             ([UIColor redColor])
#define kColor_whiteColor           ([UIColor whiteColor])
#define kColor_blackColor           ([UIColor blackColor])
#define kColor_yellowColor          ([UIColor yellowColor])
#define kColor_blueColor            ([UIColor blueColor])
#define kColor_darkGrayColor        ([UIColor darkGrayColor])
#define kColor_lightGrayColor       ([UIColor lightGrayColor])
#define kColor_brownColor           ([UIColor brownColor])
#define kColor_orangeColor          ([UIColor orangeColor])


/*********************** Font ***************************/
#pragma mark- Font
#define K_FONT(size)            ([UIFont systemFontOfSize:size])
#define K_FONT_BOLD(size)       ([UIFont boldSystemFontOfSize:size])
// 大小-细体
#define kFontSize9              ([UIFont systemFontOfSize:9.0])         /// 9号字体
#define kFontSize10             ([UIFont systemFontOfSize:10.0])        /// 10号字体
#define kFontSize11             ([UIFont systemFontOfSize:11.0])        /// 11号字体
#define kFontSize12             ([UIFont systemFontOfSize:12.0])        /// 12号字体
#define kFontSize13             ([UIFont systemFontOfSize:13.0])        /// 13号字体
#define kFontSize14             ([UIFont systemFontOfSize:14.0])        /// 14号字体
#define kFontSize15             ([UIFont systemFontOfSize:15.0])        /// 15号字体
#define kFontSize16             ([UIFont systemFontOfSize:16.0])        /// 16号字体
#define kFontSize17             ([UIFont systemFontOfSize:17.0])        /// 17号字体
#define kFontSize18             ([UIFont systemFontOfSize:18.0])        /// 18号字体
#define kFontSize19             ([UIFont systemFontOfSize:19.0])        /// 19号字体
#define kFontSize20             ([UIFont systemFontOfSize:20.0])        /// 20号字体
#define kFontSize21             ([UIFont systemFontOfSize:21.0])        /// 21号字体
#define kFontSize22             ([UIFont systemFontOfSize:22.0])        /// 22号字体
#define kFontSize24             ([UIFont systemFontOfSize:24.0])        /// 24号字体
#define kFontSize25             ([UIFont systemFontOfSize:25.0])        /// 25号字体
#define kFontSize30             ([UIFont systemFontOfSize:30.0])        /// 30号字体
// 大小-粗体
#define kFontSizeBold10         ([UIFont boldSystemFontOfSize:10.0])    /// 10号粗字体
#define kFontSizeBold11         ([UIFont boldSystemFontOfSize:11.0])    /// 11号粗字体
#define kFontSizeBold12         ([UIFont boldSystemFontOfSize:12.0])    /// 12号粗字体
#define kFontSizeBold13         ([UIFont boldSystemFontOfSize:13.0])    /// 13号粗字体
#define kFontSizeBold14         ([UIFont boldSystemFontOfSize:14.0])    /// 14号粗字体
#define kFontSizeBold15         ([UIFont boldSystemFontOfSize:15.0])    /// 15号粗字体
#define kFontSizeBold16         ([UIFont boldSystemFontOfSize:16.0])    /// 16号粗字体
#define kFontSizeBold17         ([UIFont boldSystemFontOfSize:17.0])    /// 17号粗字体
#define kFontSizeBold18         ([UIFont boldSystemFontOfSize:18.0])    /// 18号粗字体
#define kFontSizeBold19         ([UIFont boldSystemFontOfSize:19.0])    /// 19号粗字体
#define kFontSizeBold20         ([UIFont boldSystemFontOfSize:20.0])    /// 20号字粗体
#define kFontSizeBold21         ([UIFont boldSystemFontOfSize:21.0])    /// 21号字粗体


/*********************** Date ***************************/
#pragma mark- Date
#define kDateFormatDefault          @"yyyy-MM-dd HH:mm:ss"
#define kDateFormat_yyMdHm          @"yy-MM-dd HH:mm"
#define kDateFormat_yyyyMdHm        @"yyyy-MM-dd HH:mm"
#define kDateFormat_yMd             @"yyyy-MM-dd"
#define kDateFormat_MdHms           @"MM-dd HH:mm:ss"
#define kDateFormat_MdHm            @"MM-dd HH:mm"
#define kDateFormatTime             @"HH:mm:ss"
#define kDateFormat_Hm              @"HH:mm"
#define kDateFormat_Md              @"MM-dd"
#define kDateFormat_yyMd            @"yy-MM-dd"
#define kDateFormat_YYMMdd          @"yyyyMMdd"
#define kDateFormat_yyyyMdHms       @"yyyyMMddHHmmss"
#define kDateFormat_MMMddyyyymmss   @"MMM dd,yyyy mm:ss"          // add by Long


#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
#define MM_TEXTSIZE(text, font) [text length] > 0 ? [text \
sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero;
#else
#define MM_TEXTSIZE(text, font) [text length] > 0 ? [text sizeWithFont:font] : CGSizeZero;
#endif

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
#define MM_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \
attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero;
#else
#define MM_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero;
#endif

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
#define MM_DRAW_AT_POINT(text, font, point) [text \
drawAtPoint:point \
withAttributes:@{NSFontAttributeName:font}];
#else
#define MM_DRAW_AT_POINT(text, font, point) [text \
drawAtPoint:point \
withFont:font];
#endif